# File:   makefile
# Author: Chris Tonkinson
# Notes: 1) Anything with a _D or _P suffix is used for a development or production build, respectively
#        2) Anything with a _O or _S suffix refers to either an object or source file(s), respectively
#        3) TMP_FILE holds the name of the temporary file used in the compilation of the Server class.
#        4) Object and Source file listings are in alphabetical order (except for command-related code,
#           which is all grouped last, and ordered logically)

# General settings and variables...
PROJECT			= symphony
CC					= g++
FLAGS_D			= -ggdb3 -ansi -Wall -Werror -pedantic-errors
FLAGS_P			= -O3 -minline-all-stringops -funroll-loops -finline-limit=65536
CFLAGS			= `pcre-config --cflags` `mysql_config --cflags`
LIBS				= -lpcre -lpthread `pcre-config --libs` `mysql_config --libs`
SRC_DIR			= src
OBJ_DIR			= obj
BIN_DIR			= .
DB_CONF			= mysql.conf
TMP_FILE		= server_tmp.cpp

# Object/Code files for the project...
OBJ_FILES	= ${OBJ_DIR}/area.o                   \
            ${OBJ_DIR}/avatar.o                 \
            ${OBJ_DIR}/creature.o               \
            ${OBJ_DIR}/display.o                \
            ${OBJ_DIR}/exit.o                   \
            ${OBJ_DIR}/handler.o                \
            ${OBJ_DIR}/keywords.o               \
            ${OBJ_DIR}/main.o                   \
            ${OBJ_DIR}/mob.o                    \
            ${OBJ_DIR}/mysql.o                  \
            ${OBJ_DIR}/object.o                 \
            ${OBJ_DIR}/regex.o                  \
            ${OBJ_DIR}/room.o                   \
            ${OBJ_DIR}/socket.o                 \
            ${OBJ_DIR}/terrain.o                \
            ${OBJ_DIR}/terrainTable.o           \
            ${OBJ_DIR}/timer.o                  \
            ${OBJ_DIR}/world.o                  \
            ${OBJ_DIR}/commands.o               \
            ${OBJ_DIR}/commands-af.o            \
            ${OBJ_DIR}/commands-gm.o            \
            ${OBJ_DIR}/commands-np.o            \
            ${OBJ_DIR}/commands-qs.o            \
            ${OBJ_DIR}/commands-tz.o            \
            ${OBJ_DIR}/commands-aedit.o         \
            ${OBJ_DIR}/commands-medit.o         \
            ${OBJ_DIR}/commands-oedit.o         \
            ${OBJ_DIR}/commands-pedit.o         \
            ${OBJ_DIR}/commands-redit.o         \
            ${OBJ_DIR}/commands-tedit.o         \
            ${OBJ_DIR}/commandTable.o           \
            ${OBJ_DIR}/commandTable-base.o      \
            ${OBJ_DIR}/commandTable-default.o   \
            ${OBJ_DIR}/commandTable-aedit.o     \
            ${OBJ_DIR}/commandTable-medit.o     \
            ${OBJ_DIR}/commandTable-oedit.o     \
            ${OBJ_DIR}/commandTable-pedit.o     \
            ${OBJ_DIR}/commandTable-redit.o     \
            ${OBJ_DIR}/commandTable-tedit.o

SRC_FILES	= ${SRC_DIR}/area.cpp                   \
            ${SRC_DIR}/avatar.cpp                 \
            ${SRC_DIR}/creature.cpp               \
            ${SRC_DIR}/display.cpp                \
            ${SRC_DIR}/exit.cpp                   \
            ${SRC_DIR}/handler.cpp                \
            ${SRC_DIR}/keywords.cpp               \
            ${SRC_DIR}/main.cpp                   \
            ${SRC_DIR}/mob.cpp                    \
            ${SRC_DIR}/mysql.cpp                  \
            ${SRC_DIR}/object.cpp                 \
            ${SRC_DIR}/regex.cpp                  \
            ${SRC_DIR}/room.cpp                   \
            ${SRC_DIR}/socket.cpp                 \
            ${SRC_DIR}/terrain.cpp                \
            ${SRC_DIR}/terrainTable.cpp           \
            ${SRC_DIR}/timer.cpp                  \
            ${SRC_DIR}/world.cpp                  \
            ${SRC_DIR}/commands.cpp               \
            ${SRC_DIR}/commands-af.cpp            \
            ${SRC_DIR}/commands-gm.cpp            \
            ${SRC_DIR}/commands-np.cpp            \
            ${SRC_DIR}/commands-qs.cpp            \
            ${SRC_DIR}/commands-tz.cpp            \
            ${SRC_DIR}/commands-aedit.cpp         \
            ${SRC_DIR}/commands-medit.cpp         \
            ${SRC_DIR}/commands-oedit.cpp         \
            ${SRC_DIR}/commands-pedit.cpp         \
            ${SRC_DIR}/commands-redit.cpp         \
            ${SRC_DIR}/commands-tedit.cpp         \
            ${SRC_DIR}/commandTable.cpp           \
            ${SRC_DIR}/commandTable-base.cpp      \
            ${SRC_DIR}/commandTable-default.cpp   \
            ${SRC_DIR}/commandTable-aedit.cpp     \
            ${SRC_DIR}/commandTable-medit.cpp     \
            ${SRC_DIR}/commandTable-oedit.cpp     \
            ${SRC_DIR}/commandTable-pedit.cpp     \
            ${SRC_DIR}/commandTable-redit.cpp     \
            ${SRC_DIR}/commandTable-tedit.cpp


# Development build directive
# (Strict code standards enforcement, profiling, and verbose debugging, at the cost of slow and bloated object code)
dev: ${OBJ_FILES}
	rm -rf ${BIN_DIR}/${PROJECT}
#	flex src/muscl.l
#	bison -dtvy src/muscl.y
	${CC} ${CFLAGS} ${LIBS} ${FLAGS_D} ${OBJ_FILES} -o ${BIN_DIR}/${PROJECT}

# Production build directive
# (Highly optimized execution at the expense of a slow, resource-intensive compilation)
opt: ${SRC_FILES}
	rm -rf ${BIN_DIR}/${PROJECT}
#	flex src/muscl.l
#	bison -dtvy src/muscl.y
	${CC} ${CFLAGS} ${LIBS} ${FLAGS_P} ${SRC_FILES} -o ${BIN_DIR}/${PROJECT}



# Individual object file build directives...
${OBJ_DIR}/area.o: ${SRC_DIR}/area.h ${SRC_DIR}/area.cpp
	${CC} -c ${CFLAGS} ${FLAGS_D} ${SRC_DIR}/area.cpp -o ${OBJ_DIR}/area.o

${OBJ_DIR}/avatar.o: ${SRC_DIR}/avatar.h ${SRC_DIR}/avatar.cpp
	${CC} -c ${CFLAGS} ${FLAGS_D} ${SRC_DIR}/avatar.cpp -o ${OBJ_DIR}/avatar.o

${OBJ_DIR}/commands.o: ${SRC_DIR}/commands.h ${SRC_DIR}/commands.cpp
	${CC} -c ${CFLAGS} ${FLAGS_D} ${SRC_DIR}/commands.cpp -o ${OBJ_DIR}/commands.o

${OBJ_DIR}/commands-af.o: ${SRC_DIR}/commands.h ${SRC_DIR}/commands-af.cpp
	${CC} -c ${CFLAGS} ${FLAGS_D} ${SRC_DIR}/commands-af.cpp -o ${OBJ_DIR}/commands-af.o

${OBJ_DIR}/commands-gm.o: ${SRC_DIR}/commands.h ${SRC_DIR}/commands-gm.cpp
	${CC} -c ${CFLAGS} ${FLAGS_D} ${SRC_DIR}/commands-gm.cpp -o ${OBJ_DIR}/commands-gm.o

${OBJ_DIR}/commands-np.o: ${SRC_DIR}/commands.h ${SRC_DIR}/commands-np.cpp
	${CC} -c ${CFLAGS} ${FLAGS_D} ${SRC_DIR}/commands-np.cpp -o ${OBJ_DIR}/commands-np.o

${OBJ_DIR}/commands-qs.o: ${SRC_DIR}/commands.h ${SRC_DIR}/commands-qs.cpp
	${CC} -c ${CFLAGS} ${FLAGS_D} ${SRC_DIR}/commands-qs.cpp -o ${OBJ_DIR}/commands-qs.o

${OBJ_DIR}/commands-tz.o: ${SRC_DIR}/commands.h ${SRC_DIR}/commands-tz.cpp
	${CC} -c ${CFLAGS} ${FLAGS_D} ${SRC_DIR}/commands-tz.cpp -o ${OBJ_DIR}/commands-tz.o

${OBJ_DIR}/commands-aedit.o: ${SRC_DIR}/commands.h ${SRC_DIR}/commands-aedit.cpp
	${CC} -c ${CFLAGS} ${FLAGS_D} ${SRC_DIR}/commands-aedit.cpp -o ${OBJ_DIR}/commands-aedit.o

${OBJ_DIR}/commands-medit.o: ${SRC_DIR}/commands.h ${SRC_DIR}/commands-medit.cpp
	${CC} -c ${CFLAGS} ${FLAGS_D} ${SRC_DIR}/commands-medit.cpp -o ${OBJ_DIR}/commands-medit.o

${OBJ_DIR}/commands-oedit.o: ${SRC_DIR}/commands.h ${SRC_DIR}/commands-oedit.cpp
	${CC} -c ${CFLAGS} ${FLAGS_D} ${SRC_DIR}/commands-oedit.cpp -o ${OBJ_DIR}/commands-oedit.o

${OBJ_DIR}/commands-pedit.o: ${SRC_DIR}/commands.h ${SRC_DIR}/commands-pedit.cpp
	${CC} -c ${CFLAGS} ${FLAGS_D} ${SRC_DIR}/commands-pedit.cpp -o ${OBJ_DIR}/commands-pedit.o

${OBJ_DIR}/commands-redit.o: ${SRC_DIR}/commands.h ${SRC_DIR}/commands-redit.cpp
	${CC} -c ${CFLAGS} ${FLAGS_D} ${SRC_DIR}/commands-redit.cpp -o ${OBJ_DIR}/commands-redit.o

${OBJ_DIR}/commands-tedit.o: ${SRC_DIR}/commands.h ${SRC_DIR}/commands-tedit.cpp
	${CC} -c ${CFLAGS} ${FLAGS_D} ${SRC_DIR}/commands-tedit.cpp -o ${OBJ_DIR}/commands-tedit.o

${OBJ_DIR}/commandTable.o: ${SRC_DIR}/commandTable.h ${SRC_DIR}/commandTable.cpp
	${CC} -c ${CFLAGS} ${FLAGS_D} ${SRC_DIR}/commandTable.cpp -o ${OBJ_DIR}/commandTable.o

${OBJ_DIR}/commandTable-base.o: ${SRC_DIR}/commandTable.h ${SRC_DIR}/commandTable-base.cpp
	${CC} -c ${CFLAGS} ${FLAGS_D} ${SRC_DIR}/commandTable-base.cpp -o ${OBJ_DIR}/commandTable-base.o

${OBJ_DIR}/commandTable-default.o: ${SRC_DIR}/commandTable.h ${SRC_DIR}/commandTable-default.cpp
	${CC} -c ${CFLAGS} ${FLAGS_D} ${SRC_DIR}/commandTable-default.cpp -o ${OBJ_DIR}/commandTable-default.o

${OBJ_DIR}/commandTable-aedit.o: ${SRC_DIR}/commandTable.h ${SRC_DIR}/commandTable-aedit.cpp
	${CC} -c ${CFLAGS} ${FLAGS_D} ${SRC_DIR}/commandTable-aedit.cpp -o ${OBJ_DIR}/commandTable-aedit.o

${OBJ_DIR}/commandTable-medit.o: ${SRC_DIR}/commandTable.h ${SRC_DIR}/commandTable-medit.cpp
	${CC} -c ${CFLAGS} ${FLAGS_D} ${SRC_DIR}/commandTable-medit.cpp -o ${OBJ_DIR}/commandTable-medit.o

${OBJ_DIR}/commandTable-oedit.o: ${SRC_DIR}/commandTable.h ${SRC_DIR}/commandTable-oedit.cpp
	${CC} -c ${CFLAGS} ${FLAGS_D} ${SRC_DIR}/commandTable-oedit.cpp -o ${OBJ_DIR}/commandTable-oedit.o

${OBJ_DIR}/commandTable-pedit.o: ${SRC_DIR}/commandTable.h ${SRC_DIR}/commandTable-pedit.cpp
	${CC} -c ${CFLAGS} ${FLAGS_D} ${SRC_DIR}/commandTable-pedit.cpp -o ${OBJ_DIR}/commandTable-pedit.o

${OBJ_DIR}/commandTable-redit.o: ${SRC_DIR}/commandTable.h ${SRC_DIR}/commandTable-redit.cpp
	${CC} -c ${CFLAGS} ${FLAGS_D} ${SRC_DIR}/commandTable-redit.cpp -o ${OBJ_DIR}/commandTable-redit.o

${OBJ_DIR}/commandTable-tedit.o: ${SRC_DIR}/commandTable.h ${SRC_DIR}/commandTable-tedit.cpp
	${CC} -c ${CFLAGS} ${FLAGS_D} ${SRC_DIR}/commandTable-tedit.cpp -o ${OBJ_DIR}/commandTable-tedit.o

${OBJ_DIR}/creature.o: ${SRC_DIR}/creature.h ${SRC_DIR}/creature.cpp
	${CC} -c ${CFLAGS} ${FLAGS_D} ${SRC_DIR}/creature.cpp -o ${OBJ_DIR}/creature.o

${OBJ_DIR}/datum.o: ${SRC_DIR}/datum.h ${SRC_DIR}/datum.cpp
	${CC} -c ${CFLAGS} ${FLAGS_D} ${SRC_DIR}/datum.cpp -o ${OBJ_DIR}/datum.o

${OBJ_DIR}/display.o: ${SRC_DIR}/display.h ${SRC_DIR}/display.cpp
	${CC} -c ${CFLAGS} ${FLAGS_D} ${SRC_DIR}/display.cpp -o ${OBJ_DIR}/display.o

${OBJ_DIR}/exit.o: ${SRC_DIR}/exit.h ${SRC_DIR}/exit.cpp
	${CC} -c ${CFLAGS} ${FLAGS_D} ${SRC_DIR}/exit.cpp -o ${OBJ_DIR}/exit.o

${OBJ_DIR}/handler.o: ${SRC_DIR}/handler.h ${SRC_DIR}/handler.cpp
	${CC} -c ${CFLAGS} ${FLAGS_D} ${SRC_DIR}/handler.cpp -o ${OBJ_DIR}/handler.o

${OBJ_DIR}/instruction.o: ${SRC_DIR}/instruction.h ${SRC_DIR}/instruction.cpp
	${CC} -c ${CFLAGS} ${FLAGS_D} ${SRC_DIR}/instruction.cpp -o ${OBJ_DIR}/instruction.o

${OBJ_DIR}/keywords.o: ${SRC_DIR}/keywords.h ${SRC_DIR}/keywords.cpp
	${CC} -c ${CFLAGS} ${FLAGS_D} ${SRC_DIR}/keywords.cpp -o ${OBJ_DIR}/keywords.o

${OBJ_DIR}/main.o: ${SRC_DIR}/main.cpp
	${CC} -c ${CFLAGS} ${FLAGS_D} ${SRC_DIR}/main.cpp -o ${OBJ_DIR}/main.o

${OBJ_DIR}/mob.o: ${SRC_DIR}/mob.h ${SRC_DIR}/mob.cpp
	${CC} -c ${CFLAGS} ${FLAGS_D} ${SRC_DIR}/mob.cpp -o ${OBJ_DIR}/mob.o

${OBJ_DIR}/mysql.o: ${SRC_DIR}/mysql.h ${SRC_DIR}/mysql.cpp
	${CC} -c ${CFLAGS} ${FLAGS_D} ${SRC_DIR}/mysql.cpp -o ${OBJ_DIR}/mysql.o

${OBJ_DIR}/object.o: ${SRC_DIR}/object.h ${SRC_DIR}/object.cpp
	${CC} -c ${CFLAGS} ${FLAGS_D} ${SRC_DIR}/object.cpp -o ${OBJ_DIR}/object.o

${OBJ_DIR}/room.o: ${SRC_DIR}/room.h ${SRC_DIR}/room.cpp
	${CC} -c ${CFLAGS} ${FLAGS_D} ${SRC_DIR}/room.cpp -o ${OBJ_DIR}/room.o

${OBJ_DIR}/regex.o: ${SRC_DIR}/regex.h ${SRC_DIR}/regex.cpp
	${CC} -c ${CFLAGS} ${FLAGS_D} ${SRC_DIR}/regex.cpp -o ${OBJ_DIR}/regex.o

${OBJ_DIR}/socket.o: ${SRC_DIR}/socket.h ${SRC_DIR}/socket.cpp
	${CC} -c ${CFLAGS} ${FLAGS_D} ${SRC_DIR}/socket.cpp -o ${OBJ_DIR}/socket.o

${OBJ_DIR}/terrain.o: ${SRC_DIR}/terrain.h ${SRC_DIR}/terrain.cpp
	${CC} -c ${CFLAGS} ${FLAGS_D} ${SRC_DIR}/terrain.cpp -o ${OBJ_DIR}/terrain.o

${OBJ_DIR}/terrainTable.o: ${SRC_DIR}/terrainTable.h ${SRC_DIR}/terrainTable.cpp
	${CC} -c ${CFLAGS} ${FLAGS_D} ${SRC_DIR}/terrainTable.cpp -o ${OBJ_DIR}/terrainTable.o

${OBJ_DIR}/timer.o: ${SRC_DIR}/timer.h ${SRC_DIR}/timer.cpp
	${CC} -c ${CFLAGS} ${FLAGS_D} ${SRC_DIR}/timer.cpp -o ${OBJ_DIR}/timer.o

${OBJ_DIR}/world.o: ${SRC_DIR}/world.h ${SRC_DIR}/world.cpp
	${CC} -c ${CFLAGS} ${FLAGS_D} ${SRC_DIR}/world.cpp -o ${OBJ_DIR}/world.o



# Miscellaneous directives...
clean:
	rm -f ./*~ ./gmon.out ./core ${SRC_DIR}/${TMP_FILE} ${SRC_DIR}/*.cpp~ ${SRC_DIR}/*.h~ ${OBJ_DIR}/*.o
	rm -f ${BIN_DIR}/${PROJECT}

